package com.ic.service.impl;

import com.ic.base.AbstractBaseService;
import com.ic.dao.UserInfoDao;
import com.ic.entity.UserInfo;
import com.ic.service.UserInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description: 用户信息业务类
 * Author: spark
 * Date  : 2017/6/25
 * Time  : 17:31.
 */
@Service("userInfoService")
public class UserInfoServiceImpl extends AbstractBaseService<UserInfo> implements UserInfoService {
	@Resource
	private UserInfoDao userInfoDao;

	/**
	 * 验证用户信息是否存在
	 *
	 * @param userInfo 用户信息
	 * @return UserInfo
	 */
	public UserInfo checkUserInfo(UserInfo userInfo) {
		List list = userInfoDao.selectUserInfo(userInfo);
		if (list != null && list.size() > 0)
			return (UserInfo) list.get(0);
		return null;
	}

	/**
	 * 修改管理员密码
	 *
	 * @param userInfo    用户信息
	 * @param newPassword 新密码
	 * @return 返回Map
	 */
	@Override
	@SuppressWarnings("unchecked")
	public Map updatePassword(UserInfo userInfo, String newPassword) {
		Map map = new HashMap<>();
		List list = userInfoDao.selectUserInfo(userInfo);
		if (list != null && list.size() > 0) {
			userInfo = (UserInfo)list.get(0);
			userInfo.setPassword(newPassword);
			userInfoDao.updateByPrimaryKeySelective(userInfo);
			map.put("tag", "1");
		} else
			map.put("tag", "0");
		return map;
	}
}